import pymysql

def executeDatabase(sql,param=()):#update,insert,delete
    conn = pymysql.connect("192.168.7.157", 3306, "manage", "admin", "123456")
    cursor = conn.cursor()
    ret = cursor.execute(sql, param)
    conn.commit()
    cursor.close()
    conn.close()
    return ret

def findDatabase(sql,param=()):#find
    retTuple = ()
    conn = pymysql.connect("192.168.7.157", 3306, "manage", "admin", "123456")
    cursor = conn.cursor()
    cursor.execute(sql, param)
    retTuple = cursor.fetchall()
    conn.commit()
    cursor.close()
    conn.close()
    return retTuple

def login(job):#登录验证
    user = input("请输入用户id：\n")
    passwd = input("请输入密码:\n")
    sql = "select * from user where user_id=%s and user_password=%s and user_job=%s"
    param = (user, passwd,job)
    ret = executeDatabase(sql,param)
    return ret


def officerFunc():#主管操作函数
    flag = int(input("主管界面，1查看员工信息，2查看招聘信息\n"))
    if 1 == flag:
        sql = "select * from user"
    elif 2 == flag:
        sql = "select * from resume"
    else:
        print("查询错误")
        return
    result = findDatabase(sql)
    for data in result:
        print(data)
def getPrivileges():
    sql = "select resume_principalid from resume"
    list = findDatabase(sql)
    return list

def setPrivileges(id):
    sql = "update resume set resume_principalid=%s"
    param = [id]
    executeDatabase(sql,param)
def resumeDelete():
    list = getPrivileges()
    if list:
        print("无法同时操作")
    else:
        setPrivileges(1)
        resumeID = int(i= input("输入要删除的ID：\n"))
        sql = "delete from resume where resume_id=%s"
        param = ([resumeID],)
        executeDatabase(sql, param)
        setPrivileges(0)
def staffFunc():#员工操作函数
    flag = int(input("员工界面，1添加简历，2查询简历，3删除简历，4修改简历状态"))
    if 1 == flag:
        pass
    elif 2 == flag:
        pass
    elif 3 == flag:
        resumeDelete()
    elif 4 == flag:
        pass
    else:
        print("输入错误")

def main():
    while True:
        uType = int(input("选择登录方式：1专员，2主管\n"))
        if 1 == uType:
            ret = login("专员")
            if ret > 0:#专员通过验证
                staffFunc()
            else:
                print("密码错误")
        elif 2 == uType:
            ret = login("主管")
            if ret > 0:#主管通过验证
                officerFunc()
            else:
                print("密码错误")
        else:
            print("请选择登录身份")
if __name__ == '__main__':
    main()
